<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>植百汇采购单</title>
    <script type="text/javascript" src="${ctxStatic}/plugin/layui2.0/jquery-1.10.2.min.js"></script>
    <script type="text/javascript" src="${ctxStatic}/plugin/layui2.0/layui.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/plugin/layui2.0/css/layui.css" media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>入库单readOnly</legend>
</fieldset>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">入库单编号</label>
            <div class="layui-input-inline">
                <input type="text" readonly value="${warehouseReceipt.receiptNo}" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">仓库</label>
            <div class="layui-input-inline">
                <input type="text" readonly value="${warehouseReceipt.warehouseName}" class="layui-input">
            </div>
        </div>


    </div>

    <div class="layui-form-item">

        <div class="layui-inline">
            <label class="layui-form-label">采购单编号</label>
            <div class="layui-input-inline">
                <input type="text" readonly value=" ${warehouseReceipt.purchaseNo}" class="layui-input">
            </div>
        </div>

    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea id="remarks" name="remarks"
                      readonly class="layui-textarea">${warehouseReceipt.remarks}</textarea>
        </div>
    </div>

    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>入库单明细(ps:入库时添加的SKU需要修改采购单价)</legend>
    </fieldset>

    <div class="layui-form-item">

    </div>

    <div id="purchaseOrder">


        <c:forEach items="${itemActualList}" var="i">
            <div class="layui-form-item">


                <div class="layui-inline">
                    <label class="layui-form-label">
                        <c:if test="${i.reType==0}">
                            SKU(<font style="color:gold">采购</font>)
                        </c:if>
                        <c:if test="${i.reType==1}">
                            SKU(<font style="color:red">入库</font>)
                        </c:if>
                    </label>
                    <div class="layui-input-inline">
                        <input readonly type="text" value="${i.skuName}" autocomplete="off"
                               class="layui-input">
                        <input type="hidden" name="id" id="id" value="${i.id}"/><!--主键-->
                        <input type="hidden" name="reType" id="reType" value="${i.reType}"/><!--主键-->
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">采购单价</label>
                    <div class="layui-input-block">
                        <input
                                <c:if test="${i.reType==0}">readonly</c:if>

                                type="text" value="${i.price}" id="price" name="price" autocomplete="off"
                                placeholder="请输入采购单价" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">采购数量</label>
                    <div class="layui-input-block">
                        <input readonly type="text" readonly
                        <c:if test="${i.reType==0}">
                               value="${i.num}"
                        </c:if>
                        <c:if test="${i.reType==1}">
                               value="${i.reNum}"
                        </c:if>

                               name="num" id="num" autocomplete="off"
                               placeholder="请输入采购数量" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">入库数量</label>
                    <div class="layui-input-block">
                        <input readonly type="text" name="reNum" id="reNum" value="${i.reNum}" autocomplete="off"
                               placeholder="请输入实际入库数量"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-input-block">

                    </div>
                </div>
            </div>
        </c:forEach>


    </div>


    <hr/>
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-block">
                <div onclick="subForm()" class="layui-btn">保存</div>
                <div onclick="reBack()" class="layui-btn layui-btn-primary">返回</div>
            </div>
        </div>
    </div>
</form>

</body>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //交货日期
        laydate.render({
            elem: '#deliveryDate'
        });

    });
</script>
<script>
    function subForm() {
        //询问框
        layer.confirm('确定需要提交吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            add();
        }, function(){

        });
    }

    function add() {
        var purchaseOrder = new Object();

        //采购明细单
        var purchaseOrderItems = $("#purchaseOrder").find(".layui-form-item");
        var orderItems = new Array();
        var orderItem;
        for (var i = 0; i < purchaseOrderItems.length; i++) {
            orderItem = new Object();
            var reType=$(purchaseOrderItems[i]).find("#reType").val();
            if(reType==1){
                orderItem.id=$(purchaseOrderItems[i]).find("#id").val();
                orderItem.price=$(purchaseOrderItems[i]).find("#price").val();
                orderItems.push(orderItem);
            }
        }
        purchaseOrder.items = orderItems;
        var fromData = new FormData();

        fromData.append("jsons", JSON.stringify(purchaseOrder));
        //提交数据
        $.ajax({
            url: "${ctx}/warehouse/warehouseReceipt/saveReceipt",
            type: "post",
            data: fromData,
            contentType: false, // 注意这里应设为false
            processData: false,
            beforeSend: function () {
                index = layer.load(1, {
                    shade: [0.5, '#fff'] //0.1透明度的白色背景
                });
            },
            complete: function () {
                layer.close(index);
            },
            success: function (data) {
                if (data.message == "1") {
                    layer.alert('保存成功!', {
                        icon: 1,
                        title: "提示"
                    });
                    layer.close(index);
                    reBack();
                }
            },
            error: function (e) {
                layer.alert('保存失败!', {
                    icon: 2,
                    title: "提示"
                });

            }
        });


    }

    function reBack() {
        window.location.href = "${ctx}/warehouse/warehouseReceipt/list";
    }
</script>


</html>
